<?php
/**
 * File: Setting.php
 * User: Mr.Yang
 * Date: 2025/4/25 0025
 * Time: 11:10
 * Note:
 */

namespace app\admin\model;


use think\Model;

class Setting extends Model
{
    /**
     * Note: 获取配置信息
     * User: Mr.Yang
     * @param string $type
     * @return array
     */
    public function getList($type = '')
    {
        $obj = $this;
        if ($type) {
            $obj = $obj->where("type", "=", $type);
        }
        $data = $obj->select()->toArray();
        $info = array();
        foreach ($data as $k => $v) {
            $info[$v['item']] = $v['value'];
        }
        return $info;
    }

    /**
     * Note: 添加配置信息
     * User: Mr.Yang
     * @param $data
     * @return bool
     */
    public function add($data)
    {
        return $this->save($data);
    }

    /**
     * Note: 删除配置信息
     * User: Mr.Yang
     * @param $type
     * @return bool
     * @throws \Exception
     */
    public function del($type)
    {
        return $this->where('type', '=', $type)->delete();
    }
}